home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 6.8 KB | 270 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWViewAs.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWVIEWAS_H
- #include "FWViewAs.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWPOLY_H
- #include "FWPoly.h"
- #endif
-
- #ifndef FWPOLYSH_H
- #include "FWPolySh.h"
- #endif
-
- #ifndef FWREGION_H
- #include "FWRegion.h"
- #endif
-
- #ifndef FWBMPSHP_H
- #include "FWBmpShp.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWICONSH_H
- #include "FWIconSh.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__ICONS__)
- #include <Icons.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwpart2
- #endif
-
- //========================================================================================
- // CLASS FW_CViewAs
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::FW_CViewAs
- //----------------------------------------------------------------------------------------
-
- FW_CViewAs::FW_CViewAs(Environment *ev, ODTypeToken viewAs) :
- fShape(NULL),
- fViewAs(viewAs),
- fCachedUsedShape(NULL)
- {
- FW_UNUSED(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::~FW_CViewAs
- //----------------------------------------------------------------------------------------
-
- FW_CViewAs::~FW_CViewAs()
- {
- delete fShape;
- fShape = NULL;
-
- FW_SOMEnvironment ev;
- PrivInvalidateUsedShape(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::Unload
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAs::Unload(Environment* ev)
- {
- delete fShape;
- fShape = NULL;
-
- PrivInvalidateUsedShape(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::Load
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAs::Load(Environment* ev, FW_CFrame* frame)
- {
- if (fShape == NULL)
- {
- if (fViewAs == FW_CPart::fgViewAsThumbnailToken)
- {
- fThumbnailUsedRect.Set(FW_kZeroPoint, FW_IntToFixed(64), FW_IntToFixed(64));
-
- FW_CBitmap bitmap(64, 64, 8);
-
- {
- FW_CBitmapContext bc(ev, bitmap);
-
- FW_CRectShape::RenderRect(bc, fThumbnailUsedRect, FW_kFill, FW_kWhiteEraseInk);
- FW_CRectShape::RenderRect(bc, fThumbnailUsedRect, FW_kFrame);
- FW_CLineShape::RenderLine(bc, fThumbnailUsedRect.TopLeft(), fThumbnailUsedRect.BotRight());
- FW_CLineShape::RenderLine(bc, FW_CPoint(fThumbnailUsedRect.left - FW_kFixedPos1, fThumbnailUsedRect.bottom),
- FW_CPoint(fThumbnailUsedRect.right - FW_kFixedPos1, fThumbnailUsedRect.top));
-
- frame->BuildThumbnail(ev, bc, fThumbnailUsedRect);
- }
-
- fShape = FW_NEW(FW_CBitmapShape, (bitmap, fThumbnailUsedRect));
- }
- else
- {
- FW_Fixed iconSize = FW_IntToFixed((fViewAs == FW_CPart::fgViewAsSmallIconToken) ? 16 : 32);
- FW_CIcon icon = frame->GetIcon(ev, FW_FixedToInt(iconSize));
-
- FW_CRect iconRect(FW_kZeroPoint, iconSize, iconSize);
- fShape = FW_NEW(FW_CIconShape, (icon, iconRect));
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::AcquireUsedShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CViewAs::AcquireUsedShape(Environment* ev) const
- {
- FW_CViewAs* self = (FW_CViewAs*)this;
-
- if (fCachedUsedShape == NULL)
- {
- FW_ASSERT(fShape != NULL);
-
- if (fViewAs == FW_CPart::fgViewAsThumbnailToken)
- {
- self->fCachedUsedShape = ::FW_NewODShape(ev, fThumbnailUsedRect);
- }
- else
- {
- #ifdef FW_BUILD_MAC
- FW_CIcon icon;
- FW_RenderIconAlignment alignment;
- FW_RenderIconTransform transform;
- FW_CRect rect;
- ((FW_CIconShape*)fShape)->GetGeometry(icon, rect, transform, alignment);
-
- RgnHandle rgn = ::FW_NewRegion();
- short iconSize = (fViewAs == FW_CPart::fgViewAsSmallIconToken) ? 16 : 32;
- FW_CPlatformRect bounds(0, 0, iconSize, iconSize);
- ::IconSuiteToRgn(rgn, &bounds, alignment, icon.GetPlatformIcon());
-
- self->fCachedUsedShape = ::FW_NewODShape(ev, rgn);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not yet implemented");
- #endif
- }
- }
-
- fCachedUsedShape->Acquire(ev);
-
- return fCachedUsedShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAs::Draw(Environment* ev, FW_CFrame* frame, ODFacet* facet, ODShape* invalidShape)
- {
- Load(ev, frame);
-
- if (fViewAs == FW_CPart::fgViewAsSmallIconToken || fViewAs == FW_CPart::fgViewAsLargeIconToken)
- {
- FW_RenderIconTransform iconTransform = FW_kIconTransformNone;
-
- if (facet->GetHighlight(ev) == kODFullHighlight )
- iconTransform = FW_kIconTransformSelected;
-
- // Check to see if the frame has been opened into a part window.
- FW_CWindow* window = frame->GetPart(ev)->GetPartWindow(ev);
- if (window && window->IsShown(ev) )
- iconTransform |= FW_kIconTransformOpen;
-
- ((FW_CIconShape*)fShape)->SetIconTransform(iconTransform);
- }
-
- FW_CFrameContext fc(ev, facet, invalidShape);
- fShape->Render(fc);
-
- if (fViewAs == FW_CPart::fgViewAsThumbnailToken && facet->GetHighlight(ev) != kODNoHighlight)
- {
- FW_CRect bounds = frame->GetVisibleBounds(ev);
- FW_CRectShape::RenderRect(fc, bounds, FW_kFill, FW_CInk(FW_kSystemHilite));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::PrivInvalidateUsedShape
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAs::PrivInvalidateUsedShape(Environment* ev)
- {
- if (fCachedUsedShape != NULL)
- fCachedUsedShape->Release(ev);
- fCachedUsedShape = NULL;
- }